<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib uri="/WEB-INF/tlds/att.tld" prefix="att"%>
<html>
<head>
	<meta name="decorator" content="moduleEdit" />
	<script type="text/javascript" src="${staticPath}/js/brand.js"></script>
	<script type="text/javascript">
		$(document).ready(function() { 
			//$("#brandCname").focus();
			$("#brandMktshareForm").validate({
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
				
			});
			$("#save").click( function () {
				$("#brandMktshareForm").submit(); 
			});
		});

		$(function() {
			max_tr = $("#hidden_tr").closest("table").find("tr").length - 1;
		});
		
		//添加隐藏域
		function add_hidden(tId,tList) 
		{
			var tr = $(tId).clone();
			var table = $(tId).closest("table");
			//替换所有的hidden，方便spring的form绑定
			var inputs = tr.find("input");
			max_tr++;
			inputs.each(function() {
				this.id = tList + max_tr + this.id;
				this.name = tList+"[" + max_tr + "]" + this.name;
				if($("#sequence")!=null)
				{ 
					$("#sequence").html(max_tr+2);
				}
			});
			tr.show();
			table.append(tr);
		}
		function delete_tr(t,dList) 
		{
			var tr=$(t).closest("tr");
			var id=tr.find("input :first").val();
			if(id!=0){
				var val=$(dList).val();
				if(val==""){
					$(dList).val(id);
				}else{
					$(dList).val(val+","+id);
				}
			}
			tr.remove();
		}
	</script>
</head>
<body>
<div class="Report_f">
           <div class="Report_f_1">
                <div class="Report_f_title_1">品牌准入</div>
                <ul class="nav nav-tabs Report_f_title_2">
                    <li><a href="#label_1" data-toggle="tab">市场占有率</a></li>
                  </ul>
			<!-- Tab panes -->
			<div class="tab-content Report_f_title_3">
                  <div class="tab-pane active" id="label_1">
                         <div class="Report_f_title_4">
                         <form:form id="brandMktshareForm" name="brandMktshareForm" modelAttribute="brandMktshare" action="${contextPath}/biz/brand/brandmktshare/save" method="post" class="form-inline" role="form">
						 	<form:hidden path="brandAttr.id"/>
							<form:hidden path="brandAttr.brandCateId"/>
						 	<tags:message content="${message}"/>
							<table class="table table-striped table-hover o-l-table table-bordered" id="table1">
							<thead class="t_1">
								<tr>
									<th>区域</th>
									<th>省份</th>
									<th>城市</th>
									<th>商场</th>
									<th>商场业态</th>
									<th>楼层</th>
									<th>专柜位置</th>
									<th>合作方式</th>
									<th>经营面积</th>
									<th>月均销售</th>
										<th>
								<button onclick="add_hidden('#hidden_tr','brandMktshares');"
								type="button" class="btn btn-warning btn_1 pull-right">添&nbsp;加</button>
							</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${brandMktshare.brandMktshares}" varStatus="var">
									<tr>
										<form:hidden path="brandMktshares[${var.index}].id" maxlength="20" />
										<form:hidden path="brandMktshares[${var.index}].brandCateId" maxlength="20" />
										<td><form:input path="brandMktshares[${var.index}].regionNo"
												maxlength="20" class="f_5 required" /></td>
										<td><form:input path="brandMktshares[${var.index}].provinceNo"
												maxlength="20" class="f_5 required" /></td>
										<td><form:input path="brandMktshares[${var.index}].cityNo"
												maxlength="20" class="f_5 required" /></td>
										<td><form:input path="brandMktshares[${var.index}].companyNo"
										maxlength="20" class="f_5 required" /></td>
										<td><form:input path="brandMktshares[${var.index}].marketType"
												maxlength="20" class="f_5 required" /></td>
										<td><form:input path="brandMktshares[${var.index}].floor"
												maxlength="20" class="f_5 required" /></td>
										<td><form:input path="brandMktshares[${var.index}].specialPosition"
												maxlength="20" class="f_5 required" /></td>
										<td><form:input path="brandMktshares[${var.index}].cooperateMode"
												maxlength="20" class="f_5 required" /></td>
										<td><form:input path="brandMktshares[${var.index}].operateArea"
												maxlength="20" class="f_5 required" /></td>
										<td><form:input path="brandMktshares[${var.index}].sellCondition"
												maxlength="20" class="f_5 required" /></td>
										<td><input type="button" onclick="delete_tr(this,'#delIds')"
											value="删除" class="btn btn-default btn-sm"></input></td>
									</tr>
								</c:forEach>
								<!-- 隐藏行，用于新增明细start -->
								<tr style="display: none" id="hidden_tr">
									<input type="hidden" maxlength="20" value="0"
										class="form-control required" name=".id" id=".id"/>
									<input type="hidden" maxlength="20" value="${brandMktshare.brandCateId}"
										class="form-control required" name=".brandCateId" id=".brandCateId"/>
									<td><input type="text" maxlength="20" value=""
										class="form-control required" name=".regionNo" id=".regionNo"/></td>
									<td><input type="text" maxlength="20" value=""
										class="form-control required" name=".provinceNo" id=".provinceNo"/></td>
									<td><input type="text" maxlength="20" value=""
										class="form-control" name=".cityNo" id=".cityNo"/></td>
									<td><input type="text" maxlength="20" value=""
										class="form-control" name=".companyNo" id=".companyNo"/></td>
									<td><input type="text" maxlength="20" value=""
										class="form-control" name=".marketType" id=".marketType"/></td>
									<td><input type="text" maxlength="20" value=""
										class="form-control" name=".floor" id=".floor"/></td>
									<td><input type="text" maxlength="20" value=""
										class="form-control" name=".specialPosition" id=".specialPosition"/></td>
									<td><input type="text" maxlength="20" value=""
										class="form-control" name=".cooperateMode" id=".cooperateMode"/></td>
									<td><input type="text" maxlength="20" value=""
										class="form-control" name=".operateArea" id=".operateArea"/></td>
									<td><input type="text" maxlength="20" value=""
										class="form-control" name=".sellCondition" id=".sellCondition"/></td>
									<td><input type="button" onclick="delete_tr(this,'#delIds')"
										value="删除" class="btn btn-default btn-sm"/></td>
								</tr>
								<!-- 隐藏行，用于新增明细end -->
								<input type="hidden" name="delIds" id="delIds"/>
							</tbody>
						</table>
						
						<div class="f_2">
								<div class="form-group col-sm-6">
								<label for="brandAttr_shopNumber" class="col-sm-3 control-label f_4">全国门店数总计:</label>
								<div class="col-sm-9 f_6">
									<form:input id="brandAttr_shopNumber" path="brandAttr.shopNumber" maxlength="30" class="f_5 required"/>
								</div>
								</div>
							</div>
						<div class="f_2">
							<div class="form-group col-sm-6">
							<label for="brandAttr_salesTotal" class="col-sm-3 control-label f_4">全国销售业绩总计:</label>
							<div class="col-sm-9 f_6">
								 <form:input id="brandAttr_salesTotal" path="brandAttr.salesTotal" maxlength="30" class="f_5 required"/>
							</div>
							</div>
						</div>
						<div class="f_12">
						     <button type="button" class="btn btn-danger btn_5 btn_right" onclick="javascript:back('${contextPath}/biz/brand/brandcust/add');">返&nbsp;回</button>
						     <button type="button" id="save" class="btn btn-success btn_5 btn_right" <c:if test="${brandMktshare.brandCateId == null}">disabled="disabled"</c:if> >保&nbsp;存</button>
						</div>
						 </form:form>
                   </div>
              </div>
		  </div>
	</div>	
</div>   
</body>
</html>